ostree/config: Use g_autoptr instead of goto
authorMatthew Leeds <matthew.leeds@endlessm.com>
Fri, 28 Sep 2018 22:45:43 +0000 (15:45 -0700)
committerAtomic Bot <atomic-devel@projectatomic.io>
Fri, 1 Mar 2019 16:29:44 +0000 (16:29 +0000)
It seems cleaner to make the GKeyFile a g_autoptr variable and just
return rather than using the "goto out;" idiom.

Closes: #1743
Approved by: cgwalters

src/ostree/ot-builtin-config.c

index 913ed66d0141316e68a88f8c4c9903c5c0af624f..8e00af089c87cf3224cd1b57c6584f898e6cf1bc 100644 (file)
@@ -65,23 +65,22 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
 {
   g_autoptr(GOptionContext) context = NULL;
   g_autoptr(OstreeRepo) repo = NULL;
-  gboolean ret = FALSE;
   const char *op;
   const char *section_key;
   const char *value;
   g_autofree char *section = NULL;
   g_autofree char *key = NULL;
-  GKeyFile *config = NULL;
+  g_autoptr(GKeyFile) config = NULL;
 
   context = g_option_context_new ("(get KEY|set KEY VALUE|unset KEY)");
 
   if (!ostree_option_context_parse (context, options, &argc, &argv, invocation, &repo, cancellable, error))
-    goto out;
+    return FALSE;
 
   if (argc < 2)
     {
       ot_util_usage_error (context, "OPERATION must be specified", error);
-      goto out;
+      return FALSE;
     }
 
   op = argv[1];
@@ -94,7 +93,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
             {
                 g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                              "GROUP name, KEY and VALUE must be specified");
-                goto out;
+                return FALSE;
             }
           section = g_strdup(opt_group);
           key = g_strdup(argv[2]);
@@ -106,19 +105,19 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
             {
               g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "KEY and VALUE must be specified");
-              goto out;
+              return FALSE;
             }
           section_key = argv[2];
           value = argv[3];
           if(!split_key_string (section_key, &section, &key, error))
-            goto out;
+            return FALSE;
         }
 
       config = ostree_repo_copy_config (repo);
       g_key_file_set_string (config, section, key, value);
 
       if (!ostree_repo_write_config (repo, config, error))
-        goto out;
+        return FALSE;
     }
   else if (!strcmp (op, "get"))
     {
@@ -130,7 +129,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
             {
               g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "Group name and key must be specified");
-              goto out;
+              return FALSE;
             }
           section = g_strdup(opt_group);
           key = g_strdup(argv[2]);
@@ -141,17 +140,17 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
             {
               g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "KEY must be specified");
-              goto out;
+              return FALSE;
             }
           section_key = argv[2];
           if (!split_key_string (section_key, &section, &key, error))
-            goto out;
+            return FALSE;
         }
 
       readonly_config = ostree_repo_get_config (repo);
       value = g_key_file_get_string (readonly_config, section, key, error);
       if (value == NULL)
-        goto out;
+        return FALSE;
 
       g_print ("%s\n", value);
     }
@@ -164,7 +163,7 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
             {
               g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "Group name and key must be specified");
-              goto out;
+              return FALSE;
             }
           section = g_strdup(opt_group);
           key = g_strdup(argv[2]);
@@ -175,11 +174,11 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
             {
               g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                            "KEY must be specified");
-              goto out;
+              return FALSE;
             }
           section_key = argv[2];
           if (!split_key_string (section_key, &section, &key, error))
-            goto out;
+            return FALSE;
         }
 
       config = ostree_repo_copy_config (repo);
@@ -189,23 +188,19 @@ ostree_builtin_config (int argc, char **argv, OstreeCommandInvocation *invocatio
               !g_error_matches (local_error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_GROUP_NOT_FOUND))
             {
               g_propagate_error (error, g_steal_pointer (&local_error));
-              goto out;
+              return FALSE;
             }
         }
 
       if (local_error == NULL && !ostree_repo_write_config (repo, config, error))
-        goto out;
+        return FALSE;
     }
   else
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
                    "Unknown operation %s", op);
-      goto out;
+      return FALSE;
     }
 
-  ret = TRUE;
- out:
-  if (config)
-    g_key_file_free (config);
-  return ret;
+  return TRUE;
 }